/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Trab2;

import java.util.ArrayList;

/**
 *
 * @author Hiran.Azevedo
 */
public class PasswordChecker01 implements PasswordChecker{

    /**
     *
     * @param passwd
     * @return String[0] = score String [1] = result
     */
    public ArrayList<String> checkPassword(String passwd) {
        String res;
        ArrayList<String> result = new ArrayList<>();
        int is = 0;
        is += CheckLenght(passwd);
        is += CheckLowerCase(passwd);
        is += CheckUpperCase(passwd);
        is += CheckDigits(passwd);
        is += CheckSimbs(passwd);
        is += CheckLowerAndUper(passwd);
        is += CheckLettersAndNumbers(passwd);
        is += CheckLettersAndNumbersAndSimbs(passwd);
        Integer score = new Integer(is);
        result.add(score.toString());
        if (is < 16) {
            res = "very weak";
            result.add(res);
        } else if (is > 15 && is < 25) {
            res = "weak";
            result.add(res);
        } else if (is > 24 && is < 35) {
            res = "medium";
            result.add(res);
        } else if (is > 34 && is < 45) {
            res = "strong";
            result.add(res);
        } else {
            res = "stronger";
            result.add(res);
        }
        return result;
    }

    
    
  
    @Override
    public int CheckLenght(String passwd) {
        if (passwd.length() > 16) {
            return 18;
        } else if (passwd.length() >= 8 && passwd.length() <= 16) {
            return 12;
        } else if (passwd.length() >= 6 && passwd.length() <= 7) {
            return 6;
        } else if (passwd.length() >= 5) {
            return 3;
        } else {
            return 0;
        }

    }
    
    @Override
    public int CheckLowerCase(String passwd) {
        for (char a : passwd.toCharArray()) {
            if (Character.isLetter(a)) {
                if (Character.isLowerCase(a)) {
                    return 1;
                }
            }
        }
        return 0;

    }
    
    @Override
    public int CheckUpperCase(String passwd) {
        for (char a : passwd.toCharArray()) {
            if (Character.isLetter(a)) {
                if (Character.isUpperCase(a)) {
                    return 5;
                }
            }
        }
        return 0;

    }
    
    @Override
    public int CheckDigits(String passwd) {
        int count = 0;
        for (char a : passwd.toCharArray()) {
            if (Character.isDigit(a)) {
                count += 1;
            }
        }
        if (count > 0 && count < 3) {
            return 5;
        } else if (count >= 3) {
            return 10;
        } else {
            return 0;
        }
    }
    
    @Override
    public int CheckSimbs(String passwd) {
        int count = 0, is = 0;
        for (int i = 0; i < passwd.length(); i++) {
            for (int j = 0; j < Simbolos.size(); j++) {
                Character letra = passwd.charAt(i);
                if (letra.toString() == null ? Simbolos.get(j) == null : letra.toString().equals(Simbolos.get(j))) {
                    count++;
                }
            }
        }

        if (count >= 1) {
            is = (is + 5);

        }

        if (count >= 2) {
            is = (is + 5);

        }

        return is;

    }

    private int CheckLowerAndUper(String passwd) {
        if (CheckLowerCase(passwd) != 0 && CheckUpperCase(passwd) != 0) {
            return 2;
        } else {
            return 0;
        }
    }

    private int CheckLettersAndNumbers(String passwd) {
        if (CheckLowerCase(passwd) != 0 && CheckUpperCase(passwd) != 0 && CheckDigits(passwd) != 0) {
            return 2;
        } else {
            return 0;
        }
    }

    private int CheckLettersAndNumbersAndSimbs(String passwd) {
        if (CheckLowerCase(passwd) != 0 && CheckUpperCase(passwd) != 0 && CheckDigits(passwd) != 0 && CheckSimbs(passwd) != 0) {
            return 2;
        } else {
            return 0;
        }
    }
}
